Add #parse_type#11126
Conversation
|
We should additionally disallow any extra unparsed tokens before or after the type name. |
|
Do we think using |
|
Maybe we can just rescue any parse exception an raise a new error that just states that it's an invalid type name. Perhaps the original message can be attached for context. |
|
@straight-shoota Yea that was a good call. Also makes it possible to include the invalid type name in the exception message and properly points to the call site. |
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
|
Needs a rebase after #10498 |
|
What about making it a top-level method? |
|
Yes, I was going to ask about that, too. cf #11117 (comment) |
|
Fine with me. However, is the expectation that Also, I'm assuming this should be restricted to |
|
Semantics should stay the same, i.e. return |
|
Anything left to do here? |
|
Might want to add test cases for Also it is worth noting that technically |
|
Bump. Another review would be 🙏. |
Co-authored-by: Ary Borenszweig <asterite@gmail.com>
| # {{ parse_type("MissingType").resolve }} # => Error: undefined constant MissingType | ||
| # {{ parse_type("UNKNOWN_CONST").resolve }} # => Error: undefined constant UNKNOWN_CONST | ||
| # ``` | ||
| def parse_type(type_name : StringLiteral) : Path | Generic |
There was a problem hiding this comment.
There was a problem hiding this comment.
Hmm, thoughts on just adding them to the union to be more clear what it could return?
There was a problem hiding this comment.
This is just a minor thing, so we can merge this right away and always improve the docs later on.
There was a problem hiding this comment.
I already had it done, plus addressed your other comment, so I just pushed it up. Should be good to go now.
Don't skip `;;` when parsing type name
straight-shoota
left a comment
There was a problem hiding this comment.
Two small suggestions, otherwise looks good 👍
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
First pass at
StringLiteral#parse_type_name. One thing I realized is this also allows resolving constants, but that's probably fine?Resolves #11117